#include <iostream>
#include <queue>
#include <vector>

using std::cin;
using std::cout;
using std::queue;
using std::vector;
#define lld long long

void sol() {
  int n, m;
  cin >> n >> m;
  int floyd[109][109];
  for (int i = 1; i < 100; ++i)
    for (int j = 1; j < 100; ++j)
      floyd[i][j] = 0;
  while (m--) {
    int a, b;
    cin >> a >> b;
    floyd[a][b] = 1;
  }
  for (int i = 1; i < n + 1; ++i)
    for (int k = 1; k < n + 1; ++k)
      for (int j = 1; j < n + 1; ++j) {
        if (floyd[i][k] && floyd[k][j]) {
          floyd[i][j] = 1;
        }
      }
  int ans = 0;
  int num = (n - 1) / 2;

  for (int i = 1; i < n + 1; ++i) {
    int large = 0, small = 0;
    for (int j = 1; j < n + 1; ++j) {
      if (floyd[i][j])
        large++;
      if (floyd[j][i])
        small++;
    }
    if (large == num and small == num) {
      ans = i;
      break;
    }
  }
  cout << ans << std::endl;
}
int main() {
  int T = 1;
  cin >> T;
  while (T--) {
    sol();
  }
}